const partnerID = "YZJGFVKD"
const serviceCode = "EXP_RECE_SEARCH_ROUTES"
const verifyCode = "8zSrx8MVyyO0TB9fKVVvkwHX2X7npXUs"
import md5 from "./md5"
if (typeof btoa === 'undefined') {
    global.btoa = function (str) {
        return new Buffer.from(str, "binary").toString('base64');
    };
}
// 将字符串转换为base64编码
export function stringToBase64(str) {
	return btoa(unescape(encodeURIComponent(str)));
}

export function getInfo(orderCode, phone) {
	let msgData = {
		trackingType: "1",
		trackingNumber: orderCode,
		checkPhoneNo: phone
	}
	let timestamp = Date.now()
	let msgDigest = md5.hex_md5(JSON.stringify(msgData) + timestamp + verifyCode)
	msgDigest = stringToBase64(msgDigest)
	let data1 =  {
		partnerID,
		serviceCode,
		requestID: "test" + Math.random() * 10000,
		timestamp,
		msgData,
		msgDigest
	}
	console.log("哈哈哈"+JSON.stringify(data1))
	uni.request({
		url: "https://bspgw.sf-express.com/std/service",
		method: "POST",
		header: {
			"content-type": "application/x-www-form-urlencoded"
		},
		data: {
			partnerID,
			serviceCode,
			requestID: "test" + Math.random() * 10000,
			timestamp,
			msgData,
			msgDigest
		},
		success(res) {
			console.log("success :", JSON.stringify(res.data));
		},
	})
}